package com.tn.shirojwt.dao;

import com.tn.shirojwt.bean.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * @author lxw
 * @create 2020-03-16  16:05
 **/
public interface UserDao  extends JpaRepository<User, Long>, JpaSpecificationExecutor<User> {
    /**
     * 获得密码
     * 获取用户信息
     */
//    @Query(" select e.password from User e where e.userName ORDER BY e.createTime DESC ")
    User findByUserName(String userName);

    /**
     * 修改密码
     */
    @Modifying
    @Query(value = " update user set password=?2 where user_name = ?1 ",nativeQuery = true)
    int updatePassword( String username, String newPassword);

    /**
     * 获得存在的用户
     */
    @Query(" select e.roleList from User e where 1=1 ORDER BY e.createTime DESC ")
    List<User> getUser();

    /**
     * 封号
     */
    @Modifying
    @Query(value = " update user set state =2 where user_name = ?1 ",nativeQuery = true)
    int banUser(String username);

//    /**
//     * 检查用户状态
//     */
//    @Query(" select e.state from User e where e.userName ORDER BY e.createTime DESC ")
//    int checkUserBanStatus(String username);

}
